<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
<link rel="stylesheet" type="text/css" href="/static/admin/style/product.css" />
</head>
<body>
<div class="main">
    <ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
        <li>产品管理</li>
        <li><a href="javascript:history.go(-2);">产品列表</a></li>
        <li><a href="javascript:history.go(-1);">选择分类</a></li>
        <li class="active">创建产品</li>
    </ol>
    <div class="main-head-info error-info bg-danger"></div>
    <div class="main-con">
        <ul class="nav nav-tabs" id="tabs">
            <li class="active"><a href="javascript:void(0)" data-id="#a">基础信息</a></li>
            <li><a href="javascript:void(0)" data-id="#b">销售信息</a></li>
            <li><a href="javascript:void(0)" data-id="#c">图文描述</a></li>
        </ul>
        <form class="form-horizontal margin-t-30" action="{{:url('/admin/product/store')}}" method="post" id="form" autocomplete="off">
            <input type="hidden" name="category_id" value="{{:Request()->category_id}}">
            <!-- 基础信息 start -->
            <div id="a" class="tab-box">
                <div class="form-group">
                    <span class="col-sm-2 control-label">产品分类：</span>
                    <div class="col-sm-8">
                    	<p class="form-control-static">{{$selected_category}} <a type="submit" class="btn btn-warning btn-xs margin-l-5" href="{{:url('/admin/product/selectCategory')}}">编辑</a></p>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><span class="color-red">*</span> 产品名：</span>
                    <div class="col-sm-4 input-group">
                        <input class="form-control" name="name">
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">品牌：</span>
                    <div class="col-sm-2 input-group">
                        <select class="form-control" name="brand_id">
                            <option value="">请选择</option>
                            {{volist name="brands" id="vo"}}
                            <option value="{{$vo.id}}">{{$vo.name}}</option>
                            {{/volist}}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><span class="color-red">*</span> 包邮：</span>
                    <div class="col-sm-8 input-group">
                        <select class="form-control width-100" name="freight">
                            <option selected="true" value="1">是</option>
                            <option value="2">否</option>
                        </select>
                        <div class="select-freight none">
                            {{if $freights}}
                            <select class="form-control" name="freight_id">
                                <option value="">选择运费模板</option>
                                {{volist name="$freights" id="vo"}}
                                <option value="{{$vo.id}}">{{$vo.name}}</option>
                                {{/volist}}
                            </select>
                            {{else}}
                            <p class="form-control-static"><a href="/admin/shipping_freight.html">请先添加运费模板</a></p>
                            {{/if}}
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">重量：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="weight"><span class="input-group-addon">克</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">体积：</span>
                    <div class="col-sm-2 input-group">
                      <input class="form-control" name="volume"><span class="input-group-addon">立方米</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">排序：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="sort">
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">状态：</span>
                    <div class="col-sm-2 input-group">
                        <select class="form-control" name="status">
                            <option value="1">上架</option>
                            <option value="0">下架</option>
                        </select>
                    </div>
                </div>
            </div>
            <!-- 基础信息 end -->
            <!-- 销售信息 start -->
            <div id="b" class="tab-box">
                <div class="form-group">
                    <span class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="不同产品模型对应不同销售规格和产品属性"></i> 模型：</span>
                    <div class="col-sm-2 input-group">
                        <select class="form-control" name="product_model_id">
                            <option value="">请选择产品模型</option>
                            {{volist name="$product_models" id="vo"}}
                            <option value="{{$vo.id}}">{{$vo.name}}</option>
                            {{/volist}}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="为空自动生成"></i> 商家编码：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="sku">
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="最终销售价格"></i> <span class="color-red">*</span> 销售价：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="sale_price">
                        <span class="input-group-addon">元</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">库存：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="stock">
                    </div>
                </div>
                <div id="product_gs" class="none">
                    <hr/>
                    <div class="form-group"><span class="col-sm-2 control-label"><strong>销售规格</strong></span></div>
                    <div class="form-group" id="product_specifications"></div>
                    <hr/>
                    <div class="form-group"><span class="col-sm-2 control-label"><strong>产品属性</strong></span></div>
                    <div class="form-group" id="product_attributes"></div>
                </div>
            </div>
            <!-- 销售信息 end -->
            <!-- 产品图片 start -->
            <div id="c" class="tab-box">
                <div class="form-group" id="product_image">
                    <span class="col-sm-2 control-label">产品图片：</span>
                    <div class="col-sm-10 input-group">
                        <div class="product_images">
                            <div class="product_image fmr wh-80x80" data-name="image[999]"></div>
                            <div class="product_image sld fmr wh-80x80" data-name="image[]"></div>
                            <div class="product_image sld fmr wh-80x80" data-name="image[]"></div>
                            <div class="product_image sld fmr wh-80x80" data-name="image[]"></div>
                            <div class="product_image sld fmr wh-80x80" data-name="image[]"></div>
                            <div class="product_image sld fmr wh-80x80" data-name="image[]"></div>
                        </div>
                    </div>
                </div>
                <!-- sku 图片处理 start -->
                <div id="sku_image">
                    <div class="form-group none" id="sku_image_switch">
                        <p class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="若未配置，默认使用主图"></i> <a class="btn btn-info btn-xs" onclick="setSkuImage();">配置规格图</a></p>
                    </div>
                    <div class="none" id="sku_image_items"></div>
                </div>
                <!-- sku 图片处理 end -->
                <div class="form-group">
                    <span class="col-sm-2 control-label">产品详情：</span>
                    <div class="col-sm-8 input-group">
                        <textarea class="summernote" name="content"></textarea>
                    </div>
                </div>
            </div>    
            <!-- 产品图片 end -->    
            <div class="foot_btn_blank"></div>
            <div class="foot_btn">
                <div class="box">
                    <button type="submit" class="btn btn-primary">提交产品信息</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="/static/admin/plugins/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript" src="/static/admin/plugins/Bootstrap/3.3.7/js/bootstrap.js"></script>
<script type="text/javascript" src="/static/admin/script/common.js"></script>
<script type="text/javascript" src="/static/admin/plugins/layer/2.4/layer.js"></script>
{{include file="shared/_jquery_validation"}}
{{include file="shared/_summernote"}}
<script type="text/javascript" src="/static/admin/script/product.js"></script>
<script type="text/javascript">
    $("#form").validate({
        rules: {
            name: { required: true },
            sale_price: { required: true },
            category_id: { required: true },
        },
        messages: {
            name: '产品名不能为空',
            sale_price: '产品销售价不能为空',
            category_id: '产品分类不能为空',
        },
        submitHandler: function () {
            layer.confirm('确认提交？', function() {
                layer.closeAll();
                var load = layer.load();
                $("#form").ajaxSubmit(function(data) {
                    layer.close(load);
                    if (data.code == 401) {
                        goLogin(); return false;
                    }
                    if (data.code == 200) {
                        layer.msg('提交成功', { time: 1500 }, function () { window.location.href = '{{:url("/admin/product")}}' });
                    } else if (data.code == 400) {
                        layer.msg(data.message); return false;
                    } else {
                        layer.msg('操作失败'); return false;
                    }
                });
            });
        },
        invalidHandler: function (form, validator) {
            goTop();
        }
    });
</script>
</body>
</html>